<template>
  <div class="app-container">
    <!--工具栏-->
    <crudOperation :permission="permission"/>
    <div class="head-container">
      <el-dialog v-dialog-drag style="width: 80vm" title="搜索" close-on-click-modal
                 :visible.sync="crud.props.searchToggle"
                 width="70%">
        <el-form size="small" label-width="70px">
          <el-row :gutter="10">
            <el-col v-if="isBusDate" span="12">
              <el-form-item label="业务日期">
                <div class="flex flex-row">
                  <el-date-picker
                    v-model="query.startDate"
                    align="right"
                    unlink-panels
                    style="width: 50%"
                    format="yyyy - MM - dd "
                    value-format="yyyy-MM-dd"
                    default-value
                    range-separator=""
                    placeholder="开始日期"
                  />
                  <el-date-picker
                    v-model="query.endDate"
                    align="right"
                    unlink-panels
                    style="width: 50%"
                    format="yyyy - MM - dd "
                    value-format="yyyy-MM-dd"
                    default-value
                    range-separator=""
                    placeholder="结束日期"
                  />
                </div>
              </el-form-item>
            </el-col>
            <el-col span="12">
              <el-form-item label="审核日期">
                <div class="flex flex-row">
                  <el-date-picker
                    v-model="query.auditStartDate"
                    align="right"
                    unlink-panels
                    style="width: 50%"
                    format="yyyy - MM - dd "
                    value-format="yyyy-MM-dd"
                    default-value
                    range-separator=""
                    placeholder="开始日期"
                  />
                  <el-date-picker
                    v-model="query.auditEndDate"
                    align="right"
                    unlink-panels
                    style="width: 50%"
                    format="yyyy - MM - dd "
                    value-format="yyyy-MM-dd"
                    default-value
                    range-separator=""
                    placeholder="结束日期"
                  />
                </div>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6">
              <el-form-item label="供应商名称" label-width="80px">
                <table-select
                  :tableColumns="[{prop:'code',label:'供应商',width:'80'},{prop:'name',label:'供应商名称',width: '320'}]"
                  :value.sync="query.customerIds"
                  placeholder="请选择供应商"
                  url="/api/dropDown/basCustomerList"
                ></table-select>
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6">
              <el-form-item label="供应商分类" label-width="80px">
                <treeselect
                  v-model="customerTypeIds"
                  :options="customerTypeList"
                  placeholder="供应商分类"
                  style="width: 100%"
                  :normalizer="normalizer"
                  multiple
                  @input="val=>getNoStr(val,'customerTypeList','customerTypeIds')"
                />
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6">
              <el-form-item label="供应商区域" label-width="80px">
                <treeselect
                  v-model="customerAreaIds"
                  :options="areaData"
                  placeholder="请选择区域"
                  style="width: 100%"
                  :normalizer="normalizer"
                  multiple
                  @input="getArea"
                />
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6">
              <el-form-item label="部门">
                <treeselect
                  v-model="query.deptIds"
                  :options="deptList"
                  placeholder="请选择部门"
                  style="width: 100%"
                  :normalizer="normalizer"
                  multiple
                  @input="val=>getNoStr(val,'deptList','deptIds')"
                />
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6">
              <el-form-item label="人员">
                <!--                  <zSelect :clearable="false" collapseTags multiple :value.sync="userIds"  url="/api/dropDown/sysUserList" style="width:  100%;"/>-->
                <table-select
                  :tableColumns="[{prop:'name',label:'人员名称',width: '280'}]"
                  :value.sync="query.userIds"
                  placeholder="请选择人员"
                  url="/api/dropDown/sysUserList"
                ></table-select>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6">
              <el-form-item label="商品名称">
                <table-select
                  :tableColumns="[{prop:'goodsCode',label:'商品编码',width:'100'},{prop:'goodsName',label:'商品名称',width: '280'}]"
                  labelKey="goodsName"
                  valueKey="goodsId"
                  :value.sync="query.goodsIds"
                  placeholder="请选择商品"
                  url="/api/dropDown/basGoodsListForAdd"
                ></table-select>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6">
              <el-form-item label="商品分类">
                <treeselect
                  v-model="goodsTypeIds"
                  :options="typeList"
                  placeholder="请选择分类"
                  style="width: 100%"
                  :normalizer="normalizer"
                  multiple
                  @input="getgoodsType"
                />
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6">
              <el-form-item label="商品品牌">
                <table-select
                  :tableColumns="[{prop:'code',label:'品牌编码',width:'100'},{prop:'name',label:'品牌名称',width: '280'}]"
                  :value.sync="query.goodsBrandIds"
                  placeholder="请选择品牌"
                  url="/api/dropDown/basGoodsBrandList"
                ></table-select>
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6">
              <el-form-item label="商品类型">
                <table-select
                  :tableColumns="[{prop:'name',label:'商品类型',width:350}]"
                  :value.sync="query.goodsTagIds"
                  placeholder="请选择分类"
                  url="/api/dropDown/basGoodsTagList"
                ></table-select>
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6">
              <el-form-item label="单据状态">
                <el-select v-model="orderStatus" collapse-tags multiple class="edit-input" placeholder="请选择单据状态"
                           style="width: 100%;">
                  <el-option
                    v-for="(item,index) in dict.common_order_status"
                    :key="index"
                    multiple
                    :label="item.label"
                    :value="item.value"
                  />
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24">
              <el-form-item label="小计列">
                <el-checkbox-group
                  v-model="groupColumns" @change="getChange" class="flex flex-row flex-wrap">
                  <el-checkbox v-for="item in groupColumnsList"
                               :disabled="item.value ==['deptId','userId']"
                               :label="item.value"
                               :key="item.value"
                               :value="item.value">{{ item.label }}
                  </el-checkbox>
                </el-checkbox-group>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row class="flex fow-reverse">
            <el-button class="filter-item" size="mini" type="primary" @click="queryReport">搜索</el-button>
            <el-button class="filter-item" plain size="mini" type="primary"
                       @click="resetQuery">重置
            </el-button>
          </el-row>
        </el-form>
      </el-dialog>

      <!-- 表格配置 -->
      <vue-context-menu :contextMenuData="contextMenuData"
                        @tableConfig="tableConfig"
                        @deletedata="deletedata"></vue-context-menu>
      <el-dialog title="表格配置"
                 :visible.sync="tableConfigShow"
                 width="60%">
        <j-table-column-config :columns.sync="crud.header" @tabSave="tabSave" @pit="pit"/>
      </el-dialog>
      <!--表格渲染-->
      <el-table ref="table" stripe border  :data="crud.data" size="small"
                style="width: 100%;" 
                @header-dragend="changeColWidth"
                show-summary
                :summary-method="sumRow"
                @row-click="crud.selectRow"
                :row-style="crud.rowClass"
                :row-class-name="crud.tableRowClassName"
                @contextmenu.native="showMenu"
                @sort-change="sortTab"
                height="700"
                @selection-change="crud.selectionChangeHandler">
        <el-table-column type="selection" width="55"/>
        <el-table-column type="index" width="55" label="序号"/>
        <el-table-column :render-header="crud.renderHeader" v-if="groupColumnsSelectList.includes('customerId')"
                         sortable="custom" :sort-orders="['descending', 'ascending', null]" prop="customerCode"
                         label="供应商编码"/>
        <el-table-column :render-header="crud.renderHeader" v-if="groupColumnsSelectList.includes('customerId')"
                         sortable="custom" :sort-orders="['descending', 'ascending', null]" prop="customerName"
                         label="供应商名称"/>
        <el-table-column :render-header="crud.renderHeader" v-if="groupColumnsSelectList.includes('customerAreaId')"
                         sortable="custom" :sort-orders="['descending', 'ascending', null]" prop="customerAreaName"
                         label="供应商区域"/>
        <el-table-column :render-header="crud.renderHeader" v-if="groupColumnsSelectList.includes('customerTypeId')"
                         sortable="custom" :sort-orders="['descending', 'ascending', null]" prop="customerTypeName"
                         label="供应商分类"/>
        <el-table-column :render-header="crud.renderHeader" v-if="groupColumnsSelectList.includes('deptId')"
                         sortable="custom" :sort-orders="['descending', 'ascending', null]" prop="deptName" label="部门"/>
        <el-table-column :render-header="crud.renderHeader" v-if="groupColumnsSelectList.includes('userId')"
                         sortable="custom" :sort-orders="['descending', 'ascending', null]" prop="userName" label="人员"/>
        <el-table-column :render-header="crud.renderHeader" v-if="groupColumnsSelectList.includes('warehouseId')"
                         sortable="custom" :sort-orders="['descending', 'ascending', null]" prop="warehouseName"
                         label="仓库"/>
        <el-table-column :render-header="crud.renderHeader" v-if="groupColumnsSelectList.includes('goodsId')"
                         sortable="custom" :sort-orders="['descending', 'ascending', null]" prop="goodsName"
                         label="商品"/>
        <el-table-column :render-header="crud.renderHeader" prop="barcode" label="条形码"/>
        <el-table-column :render-header="crud.renderHeader" v-if="groupColumnsSelectList.includes('goodsBrandId')"
                         sortable="custom" :sort-orders="['descending', 'ascending', null]" prop="goodsBrandName"
                         label="品牌"/>
        <el-table-column :render-header="crud.renderHeader" v-if="groupColumnsSelectList.includes('goodsTypeId')"
                         sortable="custom" :sort-orders="['descending', 'ascending', null]" prop="goodsTypeName"
                         label="商品分类"/>
        <el-table-column :render-header="crud.renderHeader" v-if="groupColumnsSelectList.includes('goodsTagId')"
                         sortable="custom" :sort-orders="['descending', 'ascending', null]" prop="goodsTagName"
                         label="商品类型"/>
        <el-table-column :render-header="crud.renderHeader" prop="goodsCount" label="采购数量"/>
        <el-table-column :render-header="crud.renderHeader" prop="boxCount" label="采购箱数"/>
        <el-table-column :render-header="crud.renderHeader" prop="taxAmount" label="采购金额"/>
      </el-table>
      <!--分页组件-->
      <pagination/>
      <!--      <el-pagination-->
      <!--        :current-page.sync="crud.page.page"-->
      <!--        :page-size.sync="crud.page.size"-->
      <!--        :total="crud.page.total"-->
      <!--        :page-sizes="[10, 20, 30, 40, 50, 100, 500]"-->
      <!--        layout="sizes, prev, pager, next"-->
      <!--        style="margin-top: 8px; position: fixed;bottom:35px"-->
      <!--        @size-change="onGet"-->
      <!--        @current-change="onGet"-->
      <!--      />-->
    </div>
  </div>
</template>

<script>
import crudReportBuyRank from '@/api/erp/reportBuyRank'
import CRUD, {presenter, header, form, crud} from '@crud/crud'
import rrOperation from '@crud/RR.operation'
import crudOperation from '@crud/CRUD.operation'
import udOperation from '@crud/UD.operation'
import pagination from '@crud/Pagination'

import {getBasGoodsTypeTree} from "@/api/erp/basGoodsType";
import Treeselect from '@riophae/vue-treeselect'
import {get} from '@/api/erp/reportBuyRank'
import {publicListKey} from "@/utils/key";
import {getHeaderProperties} from "@/api/erp/headerProperties";
import {tablemixins} from "@/mixins/tablemixins";
import jTableColumnConfig from "@/components/jTableColumnConfig/jTableColumnConfig";
import {basGoodsTypeTree} from "@/api/erp/basGoods";
import {getCustomerTypeTree} from "@/api/erp/basCustomerType";
import {getDepts} from "@/api/system/dept";
import {getAreaTree} from '../../../../api/erp/basCustomerArea'


// crud交由presenter持有
const defaultCrud = CRUD({
  title: '销售排名报表',
  optShow: {
    add: false,
    edit: false,
    del: false,
    download: true,
    leadingIn: false,
    enable: false,
    disable: false,
    pass: false,
    reject: false,
    invalid: false,
    recover: false,
    downloadDetail: false,
    print: false,
    printDetail: false,
  },
  // groupColumns:['deptIds','userId'],
  query: {
    groupColumns: 'customerId,goodsId'
    // startDate: new Date().toISOString().split('T')[0],
    // endDate: new Date().toISOString().split('T')[0]
  },
  url: '/api/reportBuyRank/page', sort: '',
  queryOnPresenterCreated:false,
  crudMethod: {...crudReportBuyRank}
})
const defaultForm = {
  busDate: null,
  orderType: null,
  customerId: null,
  customerCode: null,
  customerName: null,
  fCustomerIds: null,
  fCustomerCode: null,
  fCustomerName: null,
  sCustomerIds: null,
  sCustomerCode: null,
  sCustomerName: null,
  pCustomerId: null,
  pCustomerCode: null,
  pCustomerName: null,
  mCustomerId: null,
  mCustomerCode: null,
  mCustomerName: null,
  deptId: null,
  deptCode: null,
  deptName: null,
  userId: null,
  userCode: null,
  userName: null,
  warehouseId: null,
  warehouseCode: null,
  warehouseName: null,
  goodsId: null,
  goodsCode: null,
  goodsName: null,
  packageType: null,
  barcode: null,
  boxBarcode: null,
  helpSign: null,
  model: null,
  goodsBrandId: null,
  goodsBrandCode: null,
  goodsBrandName: null,
  goodsTypeId: null,
  goodsTypeCode: null,
  goodsTypeName: null,
  goodsTagId: null,
  goodsTagCode: null,
  goodsTagName: null,
  boxUnitId: null,
  boxUnitCode: null,
  boxUnitName: null,
  boxUnitCount: null,
  boxNum: null,
  mainUnitId: null,
  mainUnitCode: null,
  mainUnitName: null,
  mainUnitCount: null,
  mainNum: null,
  goodsCount: null,
  boxCount: null,
  taxAmount: null,
  noTaxAmount: null,
  tax: null,
  sendGoodsCount: null,
  sendBoxCount: null,
  sendBoxNum: null,
  sendMainNum: null,
  sendTaxAmount: null,
  sendNoTaxAmount: null,
  sendTax: null,
  returnGoodsCount: null,
  returnBoxCount: null,
  returnBoxNum: null,
  returnMainNum: null,
  returnTaxAmount: null,
  returnNoTaxAmount: null,
  returnTax: null,
  returnBottleBoxGoodsCount: null,
  returnBottleBoxBoxCount: null,
  returnBottleBoxBoxNum: null,
  returnBottleBoxMainNum: null,
  returnBottleBoxTaxAmount: null,
  returnBottleBoxNoTaxAmount: null,
  returnBottleBoxTax: null,
  acceptGoodsCount: null,
  acceptBoxCount: null,
  acceptBoxNum: null,
  acceptMainNum: null,
  acceptTaxAmount: null,
  acceptNoTaxAmount: null,
  acceptTax: null,
  cancelAmount: null,
  unCancelAmount: null,
  goodsRemark: null,
  id: null
}
export default {
  name: 'ReportSaleRank',
  components: {pagination, crudOperation, rrOperation, udOperation, Treeselect, jTableColumnConfig},
  mixins: [presenter(defaultCrud), header(), form(defaultForm), crud(), publicListKey, tablemixins],
  dicts: ['t_report_sale_statistics_order_type', 'common_order_status'],
  mounted() {
    // if(window.name == ""){
    //   console.log("首次被加载");
    //   // 在首次进入页面时我们给window.name设置一个固定值(isRefresh)
    //   window.name = "isRefresh";
    // }else if(window.name == "isRefresh"){
    //   console.log("页面被刷新");

    getBasGoodsTypeTree({size: 999}).then(res => {
      this.goodsTypeList = res.data
    })
    this.groupColumns = ['customerId', 'goodsId']
    this.query.groupColumns = 'customerId,goodsId'
    this.groupColumnsSelectList = ['customerId', 'goodsId']

    // this.crud.refresh()

    const date = new Date().toISOString().split('T')[0]
    this.dataExtent[0] = date
    this.dataExtent[1] = date
    this.crud.props.searchToggle = false
  },
  created: function () {
    this.showEmptyBox = 1
    basGoodsTypeTree().then(res => {
      this.typeList = res
    })
    getCustomerTypeTree({size: 999}).then(res => {
      this.customerTypeList = res
    })
    getAreaTree({status: 1}).then(res => {
      this.areaData = res
      this.areaList = res
    })
    // this.getAreaTree()
    getDepts({status: 1}).then(res => {
      this.deptList = res
    })
    // console.log('typelist', this.typeList)
    // console.log('customerlist', this.customerTypeList)
    // console.log('deplist', this.deptList)
    // if(window.name == ""){
    //   console.log("首次被加载");
    //   // 在首次进入页面时我们给window.name设置一个固定值(isRefresh)
    //   window.name = "isRefresh";
    // }else if(window.name == "isRefresh"){
    //   console.log("页面被刷新");
    // getBasGoodsTypeTree({size: 999}).then(res => {
    //   this.goodsTypeList = res.data
    // })
    // this.groupColumns = []
    //
    // this.groupColumnsSelectList = []
    // // }
  },
  updated() {
    // console.log('数据', this.crud)
    this.$nextTick(() => {
      this.$refs.table.doLayout()
    })
  },
  data() {
    return {
      customerTypeList:[],
      deptList:[],
      // groupColumns:['deptId'],
      areaData: [],
      customerAreaIds: [],
      typeList: [],
      customerTypeIds: [],
      fCustomerIds: [],
      total: 0,
      goodsTypeList: [],
      areaList: [],
      orderType: [],
      orderStatus: [],
      dialogVisible: false,
      dataExtent: [],
      dataExtent1: [],
      datechange: [],
      goodsTypeIds: [],
      goodsBrandIds: [],
      warehouseIds: [],
      sCustomerIds: [],
      pCustomerIds: [],
      customerIds: [],
      customerId: [],
      goodsIds: [],
      pickerOptions: {
        shortcuts: [{
          text: '最近一周',
          onClick(picker) {
            const end = new Date();
            const start = new Date();
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
            picker.$emit('pick', [start, end]);
          }
        }, {
          text: '最近一个月',
          onClick(picker) {
            const end = new Date();
            const start = new Date();
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
            picker.$emit('pick', [start, end]);
          }
        }, {
          text: '最近三个月',
          onClick(picker) {
            const end = new Date();
            const start = new Date();
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
            picker.$emit('pick', [start, end]);
          }
        }]
      },
      permission: {
        add: ['admin', 'reportSaleStatistics:add'],
        edit: ['admin', 'reportSaleStatistics:edit'],
        del: ['admin', 'reportSaleStatistics:del'],
        import: ['admin', 'reportSaleStatistics:import'],
        export: ['admin', 'reportSaleStatistics:export'],
        copy: ['admin', 'reportSaleStatistics:copy'],
        upload: ['admin', 'reportSaleStatistics:upload'],
        download: ['admin', 'reportSaleStatistics:download'],
      },
      rules: {
        goodsId: [
          {required: true, message: '商品id不能为空', trigger: 'blur'}
        ]
      },
      groupColumns: [],
      goodsId: null,
      warehouseId: null,
      storehouseId: null,
      goodsBrandId: null,
      goodsTypeId: null,
      goodsTagId: null,
      deptId: null,
      userId: null,
      barcode: null,
      fCustomerId: null,
      sCustomerId: null,
      pCustomerId: null,
      multiple: true,
      groupColumnsSelectList: [],
      groupColumnsList: [
        {
          label: '供应商',
          value: 'customerId'
        }, {
          label: '供应商区域',
          value: 'customerAreaId'
        }, {
          label: '供应商分类',
          value: 'customerTypeId'
        },
        {
          label: '部门',
          value: 'deptId'
        }, {
          label: '人员',
          value: 'userId'
        }, {
          label: '仓库',
          value: 'warehouseId'
        }, {
          label: '商品',
          value: 'goodsId'
        }, {
          label: '商品分类',
          value: 'goodsTypeId'
        }, {
          label: '商品品牌',
          value: 'goodsBrandId'
        }, {
          label: '商品类型',
          value: 'goodsTagId'
        },],
      isBusDate: true,
      dateType: '1'
    }
  },
  watch: {
    dateType(n) {
      if (n == '1') {
        this.isBusDate = true
        this.query.auditStartDate = null
        this.query.auditEndDate = null
      } else {
        this.isBusDate = false
        this.query.startDate = null
        this.query.endDate = null
      }
    },
    'groupColumnsSelectList': {
      handler(n) {
        let groupColumns = this.groupColumnsSelectList.join(',')
        this.$set(this.query, 'groupColumns', groupColumns)
      },
      deep: true
    }
  },
  methods: {
    getSelectSum(type) {
      let i = 0
      this.crud.selections.forEach(item => {
        i += item[type]
      })
      return i
    },
    getArea(val) {
      let str = ''
      console.log(val)
      val.forEach(item => {
        const itemNode = this.getTreeName(this.areaList, item)
        console.log(itemNode)
        str = this.getNode(itemNode, str)
      })
      this.query.customerAreaIds = str
    },
    sumRow({columns, data}) {
      const sums = []
      for (let i in columns) {
        const prop = this.crud.summary[columns[i].property]
        if (prop) {
          sums[i] = <p>{this.getSelectSum(columns[i].property)}
            <hr/>
            {prop}</p>
        } else {
          sums[i] = ''
        }
      }
      sums[0] =
        <p>
          选中合计
          <hr/>
          合计
        </p>
      return sums
    },
    // 获取数据前设置好接口地址
    [CRUD.HOOK.beforeRefresh]() {
      return true
    }, // 新增与编辑前做的操作
    [CRUD.HOOK.afterToCU](crud, form) {
    },
    getChange(val) {
      this.groupColumnsSelectList = val
    },
    getValue(e) {
      if (this.dataExtent) {
        this.query.startDate = this.dataExtent[0]
        this.query.endDate = this.dataExtent[1]
      } else {
        this.query.startDate = null
        this.query.endDate = null
      }
    },
    getNoStr(val, type, prop) {
      let str = ''
      val.forEach(item => {
        const itemNode = this.getTreeName(this[type], item)
        str = this.getNode(itemNode, str)
      })
      this.query[prop] = str
    },

    // getValue(e){
    //   this.query.startDate = this.dataExtent[0]
    //   this.query.endDate = this.dataExtent[1]
    // },
    onCustomerNode(node) {
      this.query.customerTypeIds = this.getNode(node, this.query.customerTypeIds ? this.query.customerTypeIds : '')
    },
    getDateChange(e) {
      this.query.auditStartDate = this.dataExtent1[0]
      this.query.auditEndDate = this.dataExtent1[1]
    },
    getgoodsType(val) {
      let str = ''
      val.forEach(item => {
        const itemNode = this.getTreeName(this.areaList, item)
        str = this.getNode(itemNode, str)
      })
      this.query.goodsTypeIds = str
      console.log(this.query.goodsTypeIds)
    },
    getTreeName(treeList, id) {
      let _this = this
      for (let i = 0; i < treeList.length; i++) {
        let treeItem = treeList[i]
        if (treeItem.id === id) {
          return treeItem
        } else {
          if (treeItem.children && treeItem.children.length > 0) {
            let res = _this.getTreeName(treeItem.children, id)
            if (res) {
              return res
            }
          }
        }
      }
    },
    getTreeName1(treeList, id) {
      let _this = this
      for (let i = 0; i < treeList.length; i++) {
        let treeItem = treeList[i]
        if (treeItem.id === id) {
          return treeItem
        } else {
          if (treeItem.children && treeItem.children.length > 0) {
            let res = _this.getTreeName(treeItem.children, id)
            if (res) {
              return res
            }
          }
        }
      }
    },
    delgoodsType(node) {
      const list = this.getNode(node, '').split(',')
      const oldList = this.query.goodsTypeIds.split(',')
      for (let i = oldList.length; i > 0; i--) {
        console.log(list)
        console.log(oldList[i])
        console.log(list.includes(oldList[i]))
        if (list.includes(oldList[i])) {
          oldList.splice(i, 1)
        }
      }
      this.query.goodsTypeIds = oldList.join(',')
      console.log(this.query.goodsTypeIds)
    },
    getNode(node, str) {
      if (node.children) {
        for (let i = 0; i < node.children.length; i++) {
          str = this.getNode(node.children[i], str)
        }
      }
      return str += node.id + ','
    },
    normalizer(node) {
      //去掉children=[]的children属性
      if (node.children == null || node.children.length == 0) {
        delete node.children;
      }
      return {
        id: node.id,
        label: node.name,
        children: node.children
      }
    },
    init() {
      this.page = 1
    },
    onGet() {
      const that = this
      get({...this.query, ...this.crud.page}).then(res => {
        that.crud.data = res.data.content
        that.crud.page.total = res.data.totalElements
        that.crud.summary = res.data.summary
      })
    },
    delareaType(node) {
      const list = this.getNode(node, '').split(',')
      const oldList = this.query.customerAreaIds.split(',')
      for (let i = oldList.length; i > 0; i--) {
        console.log(list)
        console.log(oldList[i])
        console.log(list.includes(oldList[i]))
        if (list.includes(oldList[i])) {
          oldList.splice(i, 1)
        }
      }
      this.query.customerAreaIds = oldList.join(',')
      console.log(this.query.customerAreaIds)
    },
    resetQuery() {
      this.query = {
        customerIds: null,
        customerKeyword: '',
        goodsIds: null,
        endDate: null,
        orderCode: null,
        orderType: null,
        goodsKeyword: '',
        goodsTypeIds: null,
        goodsBrandIds: null,
        orderRemark: '',
        goodsRemark: '',
        groupColumns: '',
        orderStatus: null,
        warehouseIds: null,
        sCustomerIds: null,
        pCustomerIds: null,
        startDate: null,
        auditStartDate: null,
        auditEndDate: null,
        page: 1,
        size: 10,
      }
      this.fCustomerIds = []
      this.goodsTypeIds = []
      this.orderType = []
      this.goodsBrandIds = []
      this.orderStatus = []
      this.warehouseIds = []
      this.sCustomerIds = []
      this.pCustomerIds = []
      this.dataExtent = []
      this.dataExtent1 = []
      this.customerIds = []
      this.goodsIds = []
      this.groupColumns = []
      this.groupColumnsSelectList = []
      this.customerTypeIds = []
      this.customerAreaIds = []
      this.crud.resetQuery()
      this.onGet()
    },
    queryReport() {
      this.query.orderType = this.orderType.length ? this.orderType.join(',') : ''
      // this.query.goodsBrandIds = this.goodsBrandIds.length?this.goodsBrandIds.join(','):''
      this.query.orderStatus = this.orderStatus.length ? this.orderStatus.join(',') : ''
      // this.query.warehouseIds= this.warehouseIds.length?this.warehouseIds.join(','):''
      // this.query.sCustomerIds=this.sCustomerIds.length?this.sCustomerIds.join(','):''
      // this.query.pCustomerIds=this.pCustomerIds.length?this.pCustomerIds.join(','):''
      // this.query.fCustomerIds = this.fCustomerIds.length?this.fCustomerIds.join(','):''
      // this.query.customerIds= this.customerIds.length?this.customerIds.join(','):''
      // this.query.goodsIds= this.goodsIds.length?this.goodsIds.join(','):''
      this.init()
      // this.onGet()
      this.crud.toQuery()
      this.crud.props.searchToggle = false
    },
    getgroupColumns() {
      let str = ''
      for (let i = 0; i < this.groupColumnsSelectList.length; i++) {
        const group = this.groupColumnsList.find(val => val.value == this.groupColumnsSelectList[i])
        str += i < this.groupColumnsSelectList.length ? `${group.label}:${group.value}|` : `${group.label}:${group.value}`
      }

      return str
    }
  }
}
</script>

<style scoped>
.table-img {
  display: inline-block;
  text-align: center;
  background: #ccc;
  color: #fff;
  white-space: nowrap;
  position: relative;
  overflow: hidden;
  vertical-align: middle;
  width: 32px;
  height: 32px;
  line-height: 32px;
}

.flex {
  display: flex;
}

.fow-reverse {
  flex-direction: row-reverse;
}

.float {
  float: left;
}
</style>

